package com.demo.gmall.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.demo.gmall.bean.UserAddress;
import com.demo.gmall.service.UserService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Component;

import java.util.Arrays;
import java.util.List;

@Service
@Component
public class UserServiceImpl implements UserService {

    @HystrixCommand
    public List<UserAddress> getUserAddressList(String userId) {
        UserAddress address1 = new UserAddress();
        address1.setId(1);
        address1.setUserAddress("广东省深圳市南山区");
        address1.setConsignee("张三");

        UserAddress address2 = new UserAddress();
        address2.setId(2);
        address2.setUserAddress("湖北省咸宁市通城县");
        address2.setConsignee("李四");

        if (Math.random() > 0.5) {
            throw new RuntimeException();
        }
        return Arrays.asList(address1, address2);
    }
}
